package com.cxl.other.mode;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
/* Location:           E:\work\eclipse3.6_\workspace\design_pattern\
 * Qualified Name:     com.cxl.other.mode.DOMTest
 * JD-Core Version:    0.6.1
 */
public class DOMTest {
	private String outFile = "c:\\people.xml";

	public static void main(String[] args) {
		new DOMTest();
	}

	public DOMTest() {
		try {
			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document doc = builder.newDocument();
			Element root = doc.createElement("老师");
			Element wang = doc.createElement("王");

			wang.appendChild(doc.createTextNode("我是王老师"));
			root.appendChild(wang);
			doc.appendChild(root);
			Transformer transformer = TransformerFactory.newInstance().newTransformer();
			transformer.setOutputProperty("encoding", "gb2312");
			transformer.setOutputProperty("indent", "yes");
			transformer.transform(new DOMSource(doc), new StreamResult(this.outFile));
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}
